package control.panel
{
	import events.SitEvent;
	
	import flash.events.TimerEvent;
	
	import utils.EnterFrameTimer;
	
	import view.panel.play.SitInfoPanel;

	public class SitInfoPanelControl extends PanelControl
	{
		private var timer:EnterFrameTimer;
		private var currentSitId:int;
		
		public function SitInfoPanelControl()
		{
			initPanel();
			initTimer();
			initListener();
		}
		
		private function initListener():void
		{
			_model.sitModel.addEventListener(SitEvent.SIT_INFO_DETAIL,onSitInfoDetail);
		}
		
		private function onSitInfoDetail(event:SitEvent):void
		{
			_view.sitInfoPanel.update(event.sitInfoData);
			_view.sitInfoPanel.hideLoading();
		}
		
		private function initTimer():void
		{
			timer = new EnterFrameTimer(500);
			timer.addEventListener(TimerEvent.TIMER,onTimer);
		}
		
		private function onTimer(event:TimerEvent):void
		{
			timer.reset();
			_view.sitInfoPanel.showLoading();
			_view.sitInfoPanel.open();
			_model.netRemote.sitInfoDetail(currentSitId.toString());
		}
		
		private function initPanel():void
		{
			_view.sitInfoPanel = new SitInfoPanel(this);
		}
		
		public function open(sitId:int):void
		{
			currentSitId = sitId;
			timer.start();
		}
		
		public function close():void
		{
			_view.sitInfoPanel.close();
			timer.reset();
		}
	}
}